using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class TraCuuThongTinBenhNhanDAO
    {
        public static bool Insert(TraCuuThongTinBenhNhanDTO tc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@HoTen", tc.HoTen));
                sqlparam.Add(new SqlParameter("@LoaiBenh", tc.LoaiBenh));
                sqlparam.Add(new SqlParameter("@NgayKham", tc.NgayKham));
                sqlparam.Add(new SqlParameter("@STT", tc.STT));
                sqlparam.Add(new SqlParameter("@TrieuChung", tc.TrieuChung));
                sqlparam.Add(new SqlParameter("@MAPK", tc.MAPK));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spTraCuuThongTinBenhNhanInsert",sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static bool Delete(TraCuuThongTinBenhNhanDTO tc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                
                sqlparam.Add(new SqlParameter("@STT", tc.STT));

                int n = SqlDataAccessHelper.ExecuteNoneQuery("TraCuuThongTinBenhNhanDelete", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static List<TraCuuThongTinBenhNhanDTO> Select()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTraCuuThongTinBenhNhanSelect");
            List<TraCuuThongTinBenhNhanDTO> lst = new List<TraCuuThongTinBenhNhanDTO>();
            foreach (DataRow dr in dt.Rows)
            {
                TraCuuThongTinBenhNhanDTO tc = new TraCuuThongTinBenhNhanDTO();
                tc.STT = int.Parse(dr["STT"].ToString());
                tc.HoTen = (dr["HoTen"].ToString());
                tc.NgayKham = DateTime.Parse(dr["NgayKham"].ToString());
                tc.LoaiBenh = (dr["LoaiBenh"].ToString());
                tc.TrieuChung = (dr["TrieuChung"].ToString());
                tc.MAPK = int.Parse(dr["MAPK"].ToString());
                lst.Add(tc);
            }

            return lst;
        }
        
 
    }
}
